package com.ruoyi.web.controller.system.carPack;

import java.util.List;

import com.ruoyi.common.config.HeadNum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.GetSessionValueUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.carPark.FzCarSpecial;
import com.ruoyi.system.domain.communiry.FzSCommunity;
import com.ruoyi.system.service.carPark.IFzCarSpecialService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpSession;

/**
 * 黑白名单Controller
 * 
 * @author ruoyi
 * @date 2020-03-03
 */
@Controller
@RequestMapping("/system/special")
public class FzCarSpecialController extends BaseController
{
    private String prefix = "system/carPark/special";

    @Autowired
    private IFzCarSpecialService fzCarSpecialService;

    @RequiresPermissions("system:special:view")
    @GetMapping()
    public String special()
    {
        return prefix + "/special";
    }

    /**
     * 查询黑白名单列表
     */
    @RequiresPermissions("system:special:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HttpSession session,FzCarSpecial fzCarSpecial)
    {
        startPage();
        String communityId=((FzSCommunity)session.getAttribute("ycommunity")).getCommunityId();
        fzCarSpecial.setcId(communityId);
        List<FzCarSpecial> list = fzCarSpecialService.selectFzCarSpecialList(fzCarSpecial);
        return getDataTable(list);
    }

    /**
     * 导出黑白名单列表
     */
    @RequiresPermissions("system:special:export")
    @Log(title = "黑白名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzCarSpecial fzCarSpecial)
    {
        List<FzCarSpecial> list = fzCarSpecialService.selectFzCarSpecialList(fzCarSpecial);
        ExcelUtil<FzCarSpecial> util = new ExcelUtil<FzCarSpecial>(FzCarSpecial.class);
        return util.exportExcel(list, "special");
    }

    /**
     * 新增黑白名单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存黑白名单
     */
    @RequiresPermissions("system:special:add")
    @Log(title = "黑白名单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzCarSpecial fzCarSpecial)
    {
        fzCarSpecial.setNameId(HeadNum.CAR_SPECIAL_HEAD+ DateUtils.getTimeMillis());
        fzCarSpecial.setcId(GetSessionValueUtil.getCommunity());
        fzCarSpecial.setCreateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzCarSpecialService.insertFzCarSpecial(fzCarSpecial));
    }

    /**
     * 修改黑白名单
     */
    @GetMapping("/edit/{nameId}")
    public String edit(@PathVariable("nameId") String nameId, ModelMap mmap)
    {
        FzCarSpecial fzCarSpecial = fzCarSpecialService.selectFzCarSpecialById(nameId);
        mmap.put("fzCarSpecial", fzCarSpecial);
        return prefix + "/edit";
    }

    /**
     * 修改保存黑白名单
     */
    @RequiresPermissions("system:special:edit")
    @Log(title = "黑白名单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzCarSpecial fzCarSpecial)
    {
        fzCarSpecial.setUpdateName(ShiroUtils.getSysUser().getUserName());
        return toAjax(fzCarSpecialService.updateFzCarSpecial(fzCarSpecial));
    }

    /**
     * 删除黑白名单
     */
    @RequiresPermissions("system:special:remove")
    @Log(title = "黑白名单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzCarSpecialService.deleteFzCarSpecialByIds(ids));
    }
}
